/**
 * Created by xuweijie on 17-5-13.
 */
//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
layui.use('element', function () {
    var element = layui.element();
});

//表单提交
layui.use('form', function(){
    var form = layui.form();

    //监听提交
    form.on('submit(confirmpwd)', function(data){
        var params = $.param({
            cusername:data.field.username,
            oldpassword: data.field.oldpassword,
            newpassword: data.field.newpassword,
            checkpassword: data.field.checkpassword,
        },true);
        console.log(params);
        $.ajax({
            url:'/modifypwd.action',
            type:'post',
            data:params,
            dataType: 'json',
            success:function (data) {
                if(data=="0"){
                    layer.msg("旧密码验证不通过");
                }else if(data=="1"){
                    layer.msg("两次输入密码要相同");
                }else if(data=="2"){
                    layer.msg("密码修改成功，下次请用新密码登录");
                    window.location.href = "/admin/personalcenter/PersonalDetail";
                }else{
                    layer.msg("密码修改失败");
                }
            }
        });
        return false;
    });
});
